package com.qf2.web;

import com.qf2.mapper.StudentMapper;
import com.qf2.service.OrderService;
import com.qf2.service.UserService;
import com.qf2.service.impl.ComplextObj;
import com.qf2.service.impl.ComplextObj2;
import org.apache.ibatis.session.SqlSession;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

public class UserServlet {

    public static void main(String[] args) {
     /*   //获取spring的ioc容器（工厂）
        ApplicationContext ioc = new ClassPathXmlApplicationContext("spring-ioc.xml");

        //利用工厂获取我们想要的bean对象
        UserService userService = (UserService) ioc.getBean("userService");

        System.out.println(userService);

        userService = (UserService) ioc.getBean("userService");

        System.out.println(userService);*/


       /* ClassPathXmlApplicationContext ioc = new ClassPathXmlApplicationContext("spring-ioc.xml");
        UserService userService = (UserService) ioc.getBean("userService");

        System.out.println("---------------");
        //关闭容器，容器会被销毁，容器中的所有对象也会被销毁
        ioc.close();*/

        /*ClassPathXmlApplicationContext ioc = new ClassPathXmlApplicationContext("spring-ioc.xml");
        ComplextObj complexObj = (ComplextObj) ioc.getBean("complexObj");
        System.out.println(complexObj);

        ComplextObj2 complexObj2 = (ComplextObj2) ioc.getBean("complexObj2");
        System.out.println(complexObj2);*/


        //获取orderService
//        ClassPathXmlApplicationContext ioc = new ClassPathXmlApplicationContext("spring-ioc.xml");
//        OrderService orderService = (OrderService) ioc.getBean("orderService2");
////        orderService.show();
//        System.out.println(orderService);


        ClassPathXmlApplicationContext ioc = new ClassPathXmlApplicationContext("spring-ioc.xml");
        SqlSession sqlSession = (SqlSession) ioc.getBean("sqlSession");
        StudentMapper studentMapper = sqlSession.getMapper(StudentMapper.class);
        String name = studentMapper.findNameById(1);
        System.out.println(name);
        sqlSession.close();
    }
}
